// pages/FeiSu/fsIndex/fsIndex.js
import encode from '../../../utils/base64.js';
import request from '../../../utils/config.js';
import util from '../../../utils/util.js';
let WXBizDataCrypt = require('../../../utils/RdWXBizDataCrypt.js');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    windowHeight: wx.getSystemInfoSync().windowHeight - 167,
    noSearchHeight: wx.getSystemInfoSync().windowHeight - 107,
    searchCheckHieght: wx.getSystemInfoSync().windowHeight - 100,
    projectNum: '0',
    serviceNum: '0',
    payNum: '0',
    projectSlt: true,
    serviceSlt: true,
    paySlt: true,
    ShareDocSlt: true,
    show_project: true,
    show_service: false,
    show_pay: false,
    show_ShareDoc:false,
    projectList: [],
    serviceList: [],
    payList: [],
    menuTab: "project",//项目("project"),//服务动态("service"),收支记录("pay")
    pageNum: 1,
    totalPage: "",
    searchValue: "",
    level: 0,//目录级别
    categoryIdList: [],//返回上级目录Id
    isFromOpenDoc: false,//打开文档返回后页面不要刷新
    isGetNextPage:false,
    isLoading: false,
    isHidden: false,
    searchNum: 0,//搜索结果数量
    searchNumStatus: false,//搜索结果数量显示和隐藏
    payType:'C',
  },


  searchSign: function (e) {
    this.setData({
      isHidden: false,
      searchValue: ""
    });
    if (e.currentTarget.dataset.sign == 'collect') {
      this.setData({
        projectSlt: false,
        menuTab: 'collect',
      });
      this.getcollectList(1)
    } else if (e.currentTarget.dataset.sign == 'project') {
      this.setData({
        projectSlt: true,
        menuTab: 'project',
        searchNumStatus: true,//搜索结果显示与收藏
      });
      this.getprojectList(1)
    }
  },
  isHiddenChange: function () {
    if (this.data.menuTab == 'project' || this.data.menuTab == 'collect') {
      this.setData({ isHidden: true,searchNumStatus: false })
    }
  },
  cancelSearch: function () {
    this.setData({ isHidden: false,})
  },
  delSearchValue: function () {
    this.setData({
      searchValue: ''
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let flagName = options.flagName;
    let departmentList = wx.getStorageSync("departmentList");
    console.log("departmentList===", departmentList)
    this.setData({
      defaultDepart: flagName,
      departmentList: JSON.parse(departmentList)
    });

    this.initEleWidth();
  },
  onShow: function () {
    console.log(app.globalData.listRefresh)
    if (app.globalData.listRefresh.FS && !app.globalData.listRefresh.FS.refresh) {
      this.getListItem()
      return
    }
    if (this.data.isFromOpenDoc) {
      this.setData({ isFromOpenDoc: false })
    } else {
      wx.hideShareMenu();
      app.globalData.is_clientPro_grade_change = false
      let loginUserInfo = app.globalData.loginUserInfo;
      console.log('loginUserInfo', loginUserInfo)
      this.setData({
        loginUserInfo: loginUserInfo,
        defaultName: app.globalData.userInfo.nickName,
        defaultImg: app.globalData.userInfo.avatarUrl
      })
      //开始校验看token值
      this.checkToken();
    }
  },
  getListItem(){
    let typeTab = this.data.menuTab;
    if (!app.globalData.listRefresh.FS.projectId) {
      return;
    }
    if (typeTab == 'project') {
      let bodyInfo = {
        pageNum: '1',
        pageSize: '10',
        body: {},
        type: 'project',
        litigant: this.data.searchValue || "",
        projectId: app.globalData.listRefresh.FS.projectId
      }
      let _this = this;
      console.log(bodyInfo)
      request.requestGetMis_api("flyWorkPlace/cases", wx.getStorageSync("token"), bodyInfo, (res) => {
        let _list = JSON.parse(res.data.body);
        console.log("获取项目列表成功projectId=projectId", _list)
        if (_list.length > 0) {
          _list[0].yujiyingshou = util.SYT_util.formatMoney(util.SYT_util.math.accDiv(_list[0].expectReceivableMin * 1, 10000), 2) + "-" + util.SYT_util.formatMoney(util.SYT_util.math.accDiv(_list[0].expectReceivableMax * 1, 10000), 2);
          _list[0].operTimeStr = util.timetrans(_list[0].operTime, 'day');
          _list[0].manageInfo = [];
          if (_list[0].manageInfoList && _list[0].manageInfoList.length > 0) {
            _list[0].manageInfoList.forEach((item2) => {
              if (item2.lawyerRole == '1') {
                _list[0].manageInfo.unshift(item2.lawyerName)
              } else {
                _list[0].manageInfo.push(item2.lawyerName)
              }
            })
          }
          if (_list[0].manageInfo.length > 0) {
            _list[0].manageInfo = _list[0].manageInfo.toString();
          } else {
            _list[0].manageInfo = ''
          }
          _list[0].favorImg = _list[0].isFavor == "Y" ? 'heart_slt' : 'heart'
          _list[0].manageInfo = _list[0].manageInfo.replace(/,/g, '、')
          let projectList = _this.data.projectList;
          projectList[app.globalData.listRefresh.FS.itemIndex] = _list[0]
          _this.setData({
            projectList: projectList,
          });
        }
      }, (res) => {
        console.log("获取任务列表失败=", res)
      });
    } else if (typeTab == 'collect') {
      let bodyInfo = {
        type: 'project',
        pageNum: '1',
        pageSize: '10',
        litigant: this.data.searchValue || "",
        projectId: app.globalData.listRefresh.FS.projectId
      }

      let _this = this;
      console.log(bodyInfo)
      request.requestGetMis_api("flyWorkPlace/favorList", wx.getStorageSync("token"), bodyInfo, (res) => {
        let _list = JSON.parse(res.data.body);
        console.log("获取项目列表成功projectId=projectId", _list)
        let projectList = _this.data.projectList;
        if (_list.length > 0) {
          _list[0].yujiyingshou = util.SYT_util.formatMoney(util.SYT_util.math.accDiv(_list[0].expectReceivableMin * 1, 10000), 2) + "-" + util.SYT_util.formatMoney(util.SYT_util.math.accDiv(_list[0].expectReceivableMax * 1, 10000), 2);
          _list[0].operTimeStr = util.timetrans(_list[0].operTime, 'day');
          _list[0].manageInfo = [];
          if (_list[0].manageInfoList && _list[0].manageInfoList.length > 0) {
            _list[0].manageInfoList.forEach((item2) => {
              if (item2.lawyerRole == '1') {
                _list[0].manageInfo.unshift(item2.lawyerName)
              } else {
                _list[0].manageInfo.push(item2.lawyerName)
              }
            })
          }
          if (_list[0].manageInfo.length > 0) {
            _list[0].manageInfo = _list[0].manageInfo.toString();
          } else {
            _list[0].manageInfo = ''
          }
          _list[0].favorImg = _list[0].isFavor == "Y" ? 'heart_slt' : 'heart'
          _list[0].manageInfo = _list[0].manageInfo.replace(/,/g, '、')
          projectList[app.globalData.listRefresh.FS.itemIndex] = _list[0]
        } else {
          projectList[app.globalData.listRefresh.FS.itemIndex].isFavor = "N"
          projectList[app.globalData.listRefresh.FS.itemIndex].favorImg = 'heart'
        }
        _this.setData({
          projectList: projectList,
        });
      }, (res) => {
        console.log("获取收藏列表失败=", res)
      });
    }
  },
  //检验token值
  checkToken: function () {
    let _that = this;
    app.checkGlobalToken(function (res) {
      _that.setData({
        loginUserInfo: res.loginUserInfo,
      });
      let tempList = res.tempList;
      let flagName = res.flagName;
      let jurisdiction = res.jurisdiction;
      let roleQuanxian = res.roleQuanxian;
      let department = res.department;
      if (tempList.length == 0) {
        wx.showModal({
          title: '对不起',
          content: '您的权限不足',
          confirmText: "知道了",
          showCancel: false,
          success: function (res) {
            if (res.confirm) {
              wx.redirectTo({
                url: '../../index/index',
              })
            } else if (res.cancel) {

            }
          }
        })
        return;
      }

      //校验上次记住的部门权限是否还存在
      if (jurisdiction.indexOf(roleQuanxian) < 0) {
        wx.showModal({
          title: '对不起',
          content: "您的" + department + "部门权限不足,请重新登录并选择相关部门",
          confirmText: "知道了",
          showCancel: false,
          success: function (res) {
            if (res.confirm) {
              wx.redirectTo({
                url: '../../index/index',
              })
            } else if (res.cancel) {
            }
          }
        })
        return;
      }
      _that.getStatusNum(_that.data.defaultDepart);
    }, function (res) {
      //登录超时
      wx.showModal({
        title: '登录超时',
        content: '点击确定重新登录',
        showCancel: false,
        success: function (res) {
          if (res.confirm) {
            wx.redirectTo({
              url: '../../index/index',
            })
          } else if (res.cancel) {
          }
        }
      })
    });
  },
  //获取动态数量
  getStatusNum: function (type, flag) {
    let bodyInfo = {
      type: type == 'nonLitigation' ? "project":type
    }
    let _this = this;
    console.log('flyWorkPlacebodyInfo', bodyInfo)
    request.requestGetMis_api("flyWorkPlace", wx.getStorageSync("token"), bodyInfo, (res) => {
      console.log("动态数量成功=", JSON.parse(res.data.body))
      let bodyList = JSON.parse(res.data.body);
      let projectNum = "0";
      let serviceNum = "0";
      let payNum = '0';
      bodyList.forEach(function (e) {
        if (e.trips == '项目列表') {
          projectNum = e.number + "";
        } else if (e.trips == '服务动态') {
          serviceNum = e.number + "";
        } else if (e.trips == "收支动态") {
          payNum = e.number + "";
        }
      });
      _this.setData({
        projectNum: projectNum,
        serviceNum: serviceNum,
        payNum: payNum
      });

      //任务列表("task"),//关注("collect"),客户列表("client")
      let typeTab = _this.data.menuTab;
      console.log(typeTab,flag)
      if (flag != "gz") {
        if (typeTab == "project") {
          _this.getprojectList(1);
          _this.setData({
            projectSlt: true,
            serviceSlt: false,
            paySlt: false,
            ShareDocSlt: false,
          });
        } else if (typeTab == "service") {
          this.getserviceList(1)
          _this.setData({
            projectSlt: false,
            serviceSlt: true,
            paySlt: false,
            ShareDocSlt: false,
          });
        } else if (typeTab == "pay") {
          this.getpayList(1)
          _this.setData({
            projectSlt: false,
            serviceSlt: false,
            paySlt: true,
            ShareDocSlt: false,
          });
        } else if (typeTab == "collect") {
          this.getcollectList(1)
          _this.setData({
            projectSlt: false,
            serviceSlt: false,
            paySlt: false,
            ShareDocSlt: false,
          });
        } else if (typeTab == "ShareDoc") {
          _this.getCategoryList(0, '', 1);
        }
      }
    }, (res) => {
      console.log("动态数量失败=", res)
    });
  },
  //滚动到底部
  lower: function (e) {
    console.log("底部=", e)
    let pageNum = this.data.pageNum;
    let totalPage = this.data.totalPage;
    // console.log("pageNum===", pageNum)
    // console.log("totalPage====", totalPage)
    if (pageNum < totalPage && !this.data.isLoading) {
      let typeTab = this.data.menuTab;
      if (this.data.menuTab == 'project') {
        this.getprojectList(pageNum*1+1)
      } else if (this.data.menuTab == 'service') {
        this.getserviceList(pageNum * 1 + 1)
      } else if (this.data.menuTab == 'pay') {
        this.getpayList(pageNum * 1 + 1)
      } else if (this.data.menuTab == 'collect'){
        this.getcollectList(pageNum * 1 + 1)
      }
    } else {
      //显示没有更多字样
    }
  },
  //初始化宽度
  initEleWidth: function () {
    let delBtnWidth = this.getEleWidth(this.data.delBtnWidth);
    this.setData({
      delBtnWidth: delBtnWidth
    });
  },
  //获取元素自适应后的实际宽度
  getEleWidth: function (w) {
    let real = 0;
    try {
      let res = wx.getSystemInfoSync().windowWidth;
      let scale = (750 / 2) / (w / 2);//以宽度750px设计稿做宽度的自适应
      // console.log(scale);
      real = Math.floor(res / scale);
      return real;
    } catch (e) {
      return false;
      // Do something when catch error
    }
  },
  getprojectList: function (pageNum){
    if (pageNum == 1) {
      this.setData({
        projectList: new Array(),
        searchNum: 0
      });
    }
    this.setData({
      isLoading:true,
    });
    let bodyInfo = {
      pageNum: pageNum,
      pageSize: '10',
      body:{},
      type:'project',
      litigant: this.data.searchValue||""
    }

    let _this = this;
    console.log(bodyInfo)
    request.requestGetMis_api("flyWorkPlace/cases", wx.getStorageSync("token"), bodyInfo, (res) => {
      _this.setData({
        isLoading: false,
      });
      let _list = JSON.parse(res.data.body);
      console.log("获取项目列表成功=", _list)
      if (pageNum == 1 && _list.length == 0) {
        wx.showToast({ title: '暂无数据', icon: 'none', duration: 1000 });
      }
      if (_list.length > 0) {
        let tempList = _this.data.projectList;
        _list.forEach(function (item) {
          item.yujiyingshou = util.SYT_util.formatMoney(util.SYT_util.math.accDiv(item.expectReceivableMin * 1, 10000), 2) + "-" + util.SYT_util.formatMoney(util.SYT_util.math.accDiv(item.expectReceivableMax * 1, 10000), 2);
          item.operTimeStr = util.timetrans(item.operTime,'day');
          item.manageInfo=[];
          if (item.manageInfoList && item.manageInfoList.length>0){
            item.manageInfoList.forEach((item2)=>{
              if (item2.lawyerRole=='1'){
                item.manageInfo.unshift(item2.lawyerName)
              }else{
                item.manageInfo.push(item2.lawyerName)
              }
            })
          }
          if (item.manageInfo.length>0){
            item.manageInfo = item.manageInfo.toString();
          }else{
            item.manageInfo=''
          }
          item.favorImg = item.isFavor=="Y"?'heart_slt':'heart'
          item.manageInfo=item.manageInfo.replace(/,/g,'、')
          tempList.push(item);
        });
        _this.setData({
          projectList: tempList,
          pageNum: pageNum,
          totalPage: res.data.totalPage,
          searchNum: res.data.totalNum
        });
      }
    }, (res) => {
      _this.setData({
        isLoading: false,
      });
      console.log("获取任务列表失败=", res)
    });
  }, 
  getcollectList: function (pageNum) {
    if (pageNum == 1) {
      this.setData({
        projectList: new Array(),
        searchNum: 0
      });
    }
    this.setData({
      isLoading: true,
      searchNumStatus: true,
    });
    let bodyInfo = {
      type:'project',
      pageNum: pageNum,
      pageSize: '10',
      litigant: this.data.searchValue || ""
    }

    let _this = this;
    console.log(bodyInfo)
    request.requestGetMis_api("flyWorkPlace/favorList", wx.getStorageSync("token"), bodyInfo, (res) => {
      _this.setData({
        isLoading: false,
      });
      let _list = JSON.parse(res.data.body);
      console.log("获取项目列表成功=", _list)
      if (pageNum == 1 && _list.length == 0) {
        wx.showToast({ title: '暂无数据', icon: 'none', duration: 1000 });
      }
      if (_list.length > 0) {
        let tempList = _this.data.projectList;
        _list.forEach(function (item) {
          item.yujiyingshou = util.SYT_util.formatMoney(util.SYT_util.math.accDiv(item.expectReceivableMin * 1, 10000), 2) + "-" + util.SYT_util.formatMoney(util.SYT_util.math.accDiv(item.expectReceivableMax * 1, 10000), 2);
          item.operTimeStr = util.timetrans(item.operTime, 'day');
          item.manageInfo = [];
          if (item.manageInfoList && item.manageInfoList.length > 0) {
            item.manageInfoList.forEach((item2) => {
              if (item2.lawyerRole == '1') {
                item.manageInfo.unshift(item2.lawyerName)
              } else {
                item.manageInfo.push(item2.lawyerName)
              }
            })
          }
          if (item.manageInfo.length > 0) {
            item.manageInfo = item.manageInfo.toString();
          } else {
            item.manageInfo = ''
          }
          item.favorImg = item.isFavor == "Y" ? 'heart_slt' : 'heart'
          item.manageInfo = item.manageInfo.replace(/,/g, '、')
          tempList.push(item);
        });
        _this.setData({
          projectList: tempList,
          pageNum: pageNum,
          totalPage: res.data.totalPage,
          searchNum: res.data.totalNum
        });
      }
    }, (res) => {
      _this.setData({
        isLoading: false,
      });
      console.log("获取收藏列表失败=", res)
    });
  },
  getserviceList: function (pageNum) {
    if (pageNum == 1) {
      this.setData({
        serviceList: new Array(),
        searchNum: 0
      });
    }
    this.setData({
      isLoading: true,
    });
    let bodyInfo = {
      pageNum: pageNum,
      pageSize: '10',
    }

    let _this = this;
    console.log(bodyInfo)
    request.requestGetMis_api("flyWorkPlace/projectService", wx.getStorageSync("token"), bodyInfo, (res) => {
      _this.setData({
        isLoading: false,
      });
      let _list = JSON.parse(res.data.body);
      console.log("获取服务动态成功=", _list)
      if (pageNum == 1 && _list.length == 0) {
        wx.showToast({ title: '暂无数据', icon: 'none', duration: 1000 });
      }
      if (_list.length > 0) {
        let tempList = _this.data.serviceList;
        _list.forEach(function (item) {
          item.serviceDateStr = util.dateStr(item.serviceDate);
          tempList.push(item)
        });
        _this.setData({
          serviceList: tempList,
          pageNum: pageNum,
          totalPage: res.data.totalPage,
        });
      }
    }, (res) => {
      _this.setData({
        isLoading: false,
      });
      console.log("获取任务列表失败=", res)
    });
  },
  goshouru:function(){
    if (this.data.payType == "D") {
      this.setData({ payType: "C" })
      this.getpayList(1);
    }
  },
  gozhichu: function () {
    if (this.data.payType == "C") {
      this.setData({ payType: "D" })
      this.getpayList(1);
    }
  },
  getpayList: function (pageNum) {
    if (pageNum == 1) {
      this.setData({
        payList: new Array(),
        searchNum: 0
      });
    }
    this.setData({
      isLoading: true,
    });
    let bodyInfo = {
      pageNum: pageNum,
      pageSize: '10',
      loanSign: this.data.payType
    }

    let _this = this;
    console.log(bodyInfo)
    request.requestGetMis_api("flyWorkPlace/projectAccount", wx.getStorageSync("token"), bodyInfo, (res) => {
      _this.setData({
        isLoading: false,
      });
      let _list = JSON.parse(res.data.body);
      console.log("获取收支动态成功=", _list)
      if (pageNum == 1 && _list.length == 0) {
        wx.showToast({ title: '暂无数据', icon: 'none', duration: 1000 });
      }
      if (_list.length > 0) {
        let tempList = _this.data.payList;
        _list.forEach(function (item) {
          item.operTimeStr = util.timetrans(item.operTime,'day');
          tempList.push(item);
        });
        _this.setData({
          payList: tempList,
          pageNum: pageNum,
          totalPage: res.data.totalPage,
        });
      }
    }, (res) => {
      _this.setData({
        isLoading: false,
      });
      console.log("获取任务列表失败=", res)
    });
  },
  _goproject: function(e) {
    let departName = e.detail.split("|")[0];
    let menuTab = e.detail.split("|")[1];
    this.setData({
      searchValue: ""
    });
    this.setData({
      menuTab: menuTab,
      departName:departName,
      show_project: true,
      show_service: false,
      show_pay: false,
      show_ShareDoc:false,
    })
    this.getprojectList(1);
  },
  _goservice: function (e) {
    let departName = e.detail.split("|")[0];
    let menuTab = e.detail.split("|")[1];
    this.setData({
      searchValue: ""
    });
    this.setData({
      menuTab: menuTab,
      departName: departName,
      show_project: false,
      show_service: true,
      show_pay: false,
      show_ShareDoc: false,
    })
    this.getserviceList(1);
  },
  _gopay: function (e) {
    let departName = e.detail.split("|")[0];
    let menuTab = e.detail.split("|")[1];
    this.setData({
      searchValue: ""
    });
    this.setData({
      menuTab: menuTab,
      departName: departName,
      show_project: false,
      show_service: false,
      show_pay: true,
      show_ShareDoc: false,
    })
    this.getpayList(1);
  },
  _goShareDoc: function (e) {
    let departName = e.detail.split("|")[0];
    let menuTab = e.detail.split("|")[1];
    this.setData({
      searchValue: ""
    });
    this.setData({
      menuTab: menuTab,
      departName: departName,
      show_project: false,
      show_service: false,
      show_pay: false,
      show_ShareDoc: true,
    })
    this.getCategoryList(0, "", 1);
  },
  //开始调用查询接口
  startSearchFun: function () {
    let value = this.data.searchValue;
    this.setData({
      serachFlag: 1,
      caseList: new Array(),
      searchNumStatus: true
    });
    if (this.data.menuTab == 'project' || this.data.menuTab == 'collect') {
      if (this.data.isHidden) {
        this.setData({
          isHidden: false,
        })
        if (this.data.menuTab == 'project') {
          this.getprojectList(1)
        }else if (this.data.menuTab == 'collect') {
          this.getcollectList(1)
        }
      } else {
        this.setData({ isHidden: true, })
      }
    } else if (this.data.menuTab == 'service') {
      // this.getserviceList(1)
    } else if (this.data.menuTab == 'pay') {
      // this.getpayList(1)
    } else if (this.data.menuTab == 'ShareDoc') {
      if (value) {
        this.setData({ categoryId: this.data.categoryIdList.push('none') })
        this.getCategoryList('none', 'none', 1)
      }
    }
  },
  favor:function(e){
    let index = e.currentTarget.dataset.index;
    let projectList = this.data.projectList;
    if (projectList[index].favorImg =='heart_slt'){
      projectList[index].favorImg ='heart'
      let _this = this;
      request.requestMisApi("get", "flyWorkPlace/unfavorProjects/" + projectList[index].projectId, {}, (res) => {
        console.log("收藏", res)
      }, (res) => {
        console.log("收藏失败", res)
      });
    } else {
      projectList[index].favorImg = 'heart_slt';
      let _this = this;
      request.requestMisApi("get", "flyWorkPlace/favorProjects/" + projectList[index].projectId, {}, (res) => {
        console.log("收藏", res)
      }, (res) => {
        console.log("收藏失败", res)
      });
    }
    this.setData({ projectList})
  },
  //获取搜索查询值
  getSearchValue: function (e) {
    var searchValue = e.detail.value;
    this.setData({
      searchValue: searchValue
    });
  },
  //-----------文档库-----------
  getCategoryList: function (level, categoryId, pageNum) {
    wx.showLoading({
      title: '加载中...', mask: true
    })
    this.setData({
      isGetNextPage:true,
      folderList: [],
      level: level,
    })
    if (pageNum == 1) {
      this.setData({
        docList: [],
      });
    }
    if (level == 'none') {
      this.getDocList(categoryId, pageNum);
      return;
    }
    let bodyInfo = { level: level }
    if (categoryId && categoryId != 'none' && level != '0') {
      bodyInfo.parentId = categoryId;
    }
    console.log("shareCategorys", bodyInfo)
    let _this = this;
    request.requestMisApi("get", "shareCategorys", bodyInfo, (res) => {
      wx.hideLoading();
      if (res.code == '00') {
        console.log("获取文档目录成功=", JSON.parse(res.body))
        _this.setData({
          folderList: JSON.parse(res.body),
        });
        if (categoryId) {
          _this.getDocList(categoryId, pageNum);
        } else {
          _this.setData({
            docList: [],
            isGetNextPage: false,
          });
        }
      } else {
        wx.showToast({
          title: res.msg,
          icon: 'none',
          duration: 2000
        })
      }
    }, (res) => {
      wx.hideLoading();
      console.log("获取文档目录成功=", res)
    });
  },
  getDocList: function (categoryId, pageNum) {
    wx.showLoading({
      title: '加载中...', mask: true
    })
    let bodyInfo = {
      docFileName: this.data.searchValue || "",
      pageNum: pageNum,
      pageSize: '10'
    }
    if (categoryId != 'none') {
      bodyInfo.categoryId = categoryId
    }
    console.log("shareDocs", bodyInfo)
    let _this = this;
    request.requestMisApi("get", "shareDocs", bodyInfo, (res) => {
      wx.hideLoading();
      if (res.code == '00') {
        console.log("获取文档成功=", JSON.parse(res.body))
        let docList = this.data.docList;
        JSON.parse(res.body).forEach((item) => {
          item.sizeDesc = item.docSize * 1 < 1024 ? item.docSize + 'KB' : (item.docSize / 1024).toFixed(2) + 'MB';
          item.timeDesc = util.dateStr(item.uploadDate);
          if (/.doc$/.test(item.docFileName) || /.docx$/.test(item.docFileName)) {
            item.iconImg = 'file_word';
            item.canOpen = true;
          } else if (/.xls$/.test(item.docFileName) || /.xlsx$/.test(item.docFileName)) {
            item.iconImg = 'file_exl';
            item.canOpen = true;
          } else if (/.zip$/.test(item.docFileName)) {
            item.iconImg = 'file_zip'
          } else if (/.png$/.test(item.docFileName)) {
            item.iconImg = 'file_png';
            item.canOpen = true;
          } else if (/.exe$/.test(item.docFileName)) {
            item.iconImg = 'file_exe'
          } else if (/.gif$/.test(item.docFileName)) {
            item.iconImg = 'file_gif'
          } else if (/.jpg$/.test(item.docFileName) || /.jpeg$/.test(item.docFileName)) {
            item.iconImg = 'file_jpg';
            item.canOpen = true;
          } else if (/.ios$/.test(item.docFileName)) {
            item.iconImg = 'file_ios'
          } else if (/.pdf$/.test(item.docFileName)) {
            item.iconImg = 'file_pdf';
            item.canOpen = true;
          } else if (/.ppt$/.test(item.docFileName) || /.pptx$/.test(item.docFileName)) {
            item.iconImg = 'file_ppt';
            item.canOpen = true;
          } else if (/.txt$/.test(item.docFileName)) {
            item.iconImg = 'file_txt';
          } else {
            item.iconImg = 'file_other'
          }
          docList.push(item)
        })
        _this.setData({
          docList: docList,
          pageDocNum: pageNum,
          totalDocPage: res.totalPage
        });
      } else {
        wx.showToast({
          title: res.msg,
          icon: 'none',
          duration: 2000
        })
      }
      _this.setData({
        isGetNextPage: false,
      });
    }, (res) => {
      _this.setData({
        isGetNextPage: false,
      });
      wx.hideLoading();
      console.log("获取文档成功=", res)
    });
  },
  folderClick: function (e) {
    console.log(e)
    let category = e.currentTarget.dataset.category;
    this.setData({ categoryId: this.data.categoryIdList.push(category.categoryId) })
    this.getCategoryList(category.level * 1 + 1, category.categoryId, 1)
  },
  folderBack: function () {
    if (this.data.level == 'none') {
      this.getCategoryList(0, this.data.categoryIdList[this.data.categoryIdList.length - 2], 1)
    } else {
      this.getCategoryList(this.data.level * 1 - 1, this.data.categoryIdList[this.data.categoryIdList.length - 2], 1)
    }
    this.setData({ categoryId: this.data.categoryIdList.pop() })
  },
  shareDocSearch: function () {
    if (this.data.searchValue) {
      this.setData({ categoryId: this.data.categoryIdList.push('none') })
      this.getCategoryList('none', 'none', 1)
    }
  },
  lowerShareDoc: function () {
    let pageDocNum = this.data.pageDocNum;
    let totalDocPage = this.data.totalDocPage;
    if (pageDocNum < totalDocPage && !this.data.isGetNextPage) {
      this.getCategoryList(this.data.level, this.data.categoryIdList[this.data.categoryIdList.length - 1], pageDocNum * 1 + 1)
    } else {
      //显示没有更多字样
    }
  },
  docClick(e) {
    let doc = e.currentTarget.dataset.doc
    if (doc.canOpen) {
      this.dowmloadFile(doc.docUrl, doc.docFileName)
    } else {
      wx.setClipboardData({
        data: doc.docUrl,
        success: function (res) {
          console.log(res)
          wx.showToast({
            title: '复制链接成功',
            icon: 'success',
            duration: 700
          })
          setTimeout(() => {
            wx.showModal({
              content: '该文件无法预览，文件路径已复制到剪切板，你可以打开浏览器下载',
              showCancel: false,
              success: function (res) {
                if (res.confirm) {
                  console.log('用户点击确定')
                } else if (res.cancel) {
                  console.log('用户点击取消')
                }
              }
            })
          }, 700)
        }
      })
    }
  },
  docLongpress: function (e) {
    let doc = e.currentTarget.dataset.doc
    wx.setClipboardData({
      data: doc.docUrl,
      success: function (res) {
        console.log(res)
        wx.showToast({
          title: '复制链接成功',
          icon: 'success',
          duration: 800
        })
      }
    })
  },
  //点击下载文件
  dowmloadFile: function (fileurl, docName) {
    let _this = this;
    let tempSuf = docName.split('.');
    let suffix = tempSuf[tempSuf.length - 1];
    let fileType = "doc,xls,ppt,pdf,docx,xlsx,pptx";
    let picSuffix = "bmp,jpg,png,tiff,gif,pcx,tga,exif,fpx,svg,psd,cdr,pcd,dxf,ufo,eps,ai,raw,WMF,jpeg";
    console.log("fileurl==", fileurl, docName)
    wx.showLoading({ title: ' ', mask: true })
    wx.downloadFile({
      url: fileurl, //仅为示例，并非真实的资源
      success: function (res) {
        // 只要服务器有响应数据，就会把响应内容写入文件并进入 success 回调，业务需要自行判断是否下载到了想要的内容
        console.log("读取文件成功=", res)
        // if (res.statusCode === 200) {
        var filePath = res.tempFilePath
        wx.hideLoading()
        _this.setData({ isFromOpenDoc: true })
        if (fileType.indexOf(suffix) != "-1") {
          wx.openDocument({
            filePath: filePath,
            success: function (res) {
              console.log('打开文档成功')
            }
          })
        } else if (picSuffix.indexOf(suffix.toLowerCase()) != "-1") {
          wx.previewImage({
            current: filePath, // 当前显示图片的http链接
            urls: [filePath] // 需要预览的图片http链接列表
          })
        }
      },
      fail: function (res) {
        wx.hideLoading()
        console.log("读取文件失败=", res);
      }
    })
  },
  //去详情界面
  goDetInfo: function (e) {
    // console.log(e)
    let projectId = e.currentTarget.dataset.projectid;
    app.globalData.projectId = projectId;
    app.globalData.listRefresh.FS = {
      refresh: false,
      projectId: projectId,
      itemIndex: e.currentTarget.dataset.index,
      tabtype: e.currentTarget.dataset.tabtype
    }
    wx.navigateTo({
      url: '../fsDetail/fsDetail?current=' + e.currentTarget.dataset.current,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.fstop = this.selectComponent("#fsTop");
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      searchValue: "",
    });
    this.getStatusNum(this.data.defaultDepart);
    setTimeout(function () {
      wx.showToast({
        title: '加载成功',
        icon: 'success',
        duration: 1000
      })
      wx.stopPullDownRefresh();
    }, 1000);
    console.log("执行了一次下拉刷新")
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {
  
  // }
})